package General;
import Card.*;
import java.util.ArrayList;

public class Player {
	private final Hand myHand;
	private final Board myBoard;
	private final int culture;
	private Wallet myWallet;
	private int age=0; //Archaic=0, Classical=1, Heroic=2, Mythic=3
	private int victoryPts;
	private Deck battle;
	private Card[] permanent;
	private Deck random;
	private String name;
	private final int MAX_AGE=3;	//ages start from 0 end at 3
	private int villagerCount = 0;
	private int dwarfCount =0;
	Player(int culture){
		super();
		this.name = "UnNamed";
		this.culture = culture;
		myHand = new Hand();
		myBoard = new Board(culture);
		myWallet = new Wallet(new Resource(4,4,4,4,0));	//players start with 4 resources
		setDecks();
	}
	private void setDecks(){
		//TODO Cards are immutable, allowing shallow copy
		battle = null;
		random = Culture.getRandom(culture);
		//battle = Culture.getBattle(culture);
		permanent = Culture.getPermanent();
	}
	
	public String getName(){
		return name;
	}
	public void setName(String name){
		this.name = name;
	}
	
	public int getAge()
	{
		return age;
	}//end getAge
	
	public int getCulture(){
		return culture;
	}
	public void spoil(){
		myWallet.spoilage();
	}
	public Card peekHand(int index){
		return myHand.getCard(index);
	}
	public Card playHand(int index){
		Card temp= myHand.getCard(index);
//		if(myWallet.getFunds().creditCheck(temp.getPrice())){
//		myWallet.pay(temp.getPrice(), Bank.singletonBank.getWallet());
		temp.use(this);
		myHand.deleteCard(index);
//		}
//		else{
//			//TODO UI notification
//			System.out.println("insufficient resources");
//			return null;
//		}
		//TODO try catch this
		return temp;
	}
	public void discard(int index){
		myHand.deleteCard(index);
	}
	public Card draw(int card){
		//0 = random, each permanent gets their corresponding number
		Card temp = null;
		if(card<0){
			temp = random.deal();
		}else {
			temp = permanent[card];
		}
		myHand.insertCard(temp);
		return temp;
	}
	public boolean advanceAge(){
		if (age<MAX_AGE){
			age++;
			return true;
		}else return false;
	}
	public void setAge(){
		age++;
	}
	public Wallet getWallet(){
		return myWallet;
	}
	public void recieveVictory(int pts){
		victoryPts+=pts;
	}
	public int getVictory(){
		return victoryPts;
	}
	public boolean handFull(){
		return (age+4)<=myHand.currentSize();
	}
	public int handCount(){
		return myHand.currentSize();
	}
	public Terrain getTerrain(int x, int y){
		return myBoard.getTerrain(x, y);
	}
	public Resources getTileType(int x, int y){
		return myBoard.getTileType(x,y);
	}
	public Hand getHand(){
		return myHand;
	}
	public boolean attachTile(int x, int y, Tile tile){
		return myBoard.attachTile(x, y, tile);
	}
	public Board getBoard(){
		return myBoard;
	}
	
	public void incVillager(){
		villagerCount++;
	}
	public void decVillager(){
		villagerCount--;
	}
	public int getVillagerCnt(){
		return villagerCount;
	}
	
	public void incDwarf(){
		dwarfCount++;
	}
	public void decDwarf(){
		dwarfCount--;
	}
	public int getDwarfCnt(){
		return dwarfCount;
	}
}